//
//  PointItemCell.m
//  xychain_DM_iOS
//
//  Created by Jpwang on 2018/6/1.
//  Copyright © 2018年 Jpwang. All rights reserved.
//

#import "PointItemCell.h"

@implementation PointItemCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    self.bgIv.layer.cornerRadius = globalRadius;
    self.gradientIv.image = createGradientImage(self.gradientIv.frame.size, colorWithString(@"#2dff9e"), colorWithString(@"#15c1ff"), 1);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setBlock:(void (^)(PointInfo *model))block {
    mBlock = [block copy];
}

- (void)setModel:(PointInfo *)model {
    [[RACObserve(model, device) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        NSString *str = model.device&&model.device[@"label"] ? model.device[@"label"] : model.sn;
        self.deviceLb.text = [NSString stringWithFormat:@"设备：%@", str];
    }];
    [[RACObserve(model, sn) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        self.snLb.text = [NSString stringWithFormat:@"s/n:%@", model.sn];
    }];
    
    [[RACObserve(model, point) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        NSString *text = [NSString stringWithFormat:@"%@", model.point];
        NSRange r = [text rangeOfString:@"."];
        if (r.location != NSNotFound) {
            int length = (int)MIN(text.length-r.location-1, 9);
            text = [NSString stringWithFormat:@"%@%@",[text substringToIndex:r.location+1], [text substringWithRange:NSMakeRange(r.location+1, length)]];
        }
        self.pointLb.text = text;
    }];
    
    [[RACObserve(model, settleDate) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        self.timeLb.text = model.settleDate;
    }];
    
    [[RACObserve(model, address) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        if (model.address && model.address.length>0) {
            self.descLb.text = @"收益转入绑定钱包";
            self.arrowIv.hidden = NO;
        } else {
            self.descLb.text = @"收益转入账户余额";
            self.arrowIv.hidden = YES;
        }
    }];
    
    [[[self.operateBt rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id x) {
        if (model.address && model.address.length>0) {
            if (self->mBlock) {
                self->mBlock(model);
            }
        }
    }];
}

@end
